﻿using Assets.Script.HelpSystem.AtkSystem.Base;
using Assets.Script.Human.Player;
using Assets.Script.Tools;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;

namespace Assets.Script.HelpSystem.AtkSystem.AtkWays
{
    public class AtkWayKnifeNormal : AtkWay
    {
        protected float secondTime = 0;
        protected Timer atkTimer2;
        public AtkWayKnifeNormal(PlayerBody playerBody, AtkInfo atkInfo, Dictionary<Type, int> bulletEffectLevel, int index) : base(playerBody, atkInfo, bulletEffectLevel, index)
        {
        }

        protected override void SetData(params object[] o)
        {
            base.SetData(o);
            atkWaitTime = 1f / playerBody.PlayerData.AtkSpeed / 2;
            coolTime = 1f / playerBody.PlayerData.AtkSpeed;
            attackDir = playerBody.PlayerData.AttackDir;
            dmg = bulletData.Atk * 0.8f;
            secondTime = atkWaitTime+0.2f;
        }

        protected override void AttackStart_m()
        {
            animator.SetFloat("atkSpeed", playerBody.PlayerData.AtkSpeed);
        }

        protected override void UpdateInAttack()
        {
            Attack_Invoke();
        }

        public override void AttackInterrupt()
        {
            inAttack = false;
            AttackEnd_m();
            if (atkTimer != null)
            {
                atkTimer.Stop();
            }
            if (atkTimer2 != null)
            {
                atkTimer2.Stop();
            }
        }

        /// <summary>
        /// 攻击动作，制作子弹,控制弹道,播放音效等，
        /// </summary>
        protected override void Attack_Normal()
        {
            animator.SetTrigger("atkStart");

            atkTimer = new Timer(atkWaitTime, false, TimeData.One, () =>
            {
                if (attackDir.forward > 0)
                    CreateBulletWithDirAndNum(playerBody.fire_forward, ref attackDir.forward);
                if (attackDir.back > 0)
                    CreateBulletWithDirAndNum(playerBody.fire_back, ref attackDir.back);
                if (attackDir.left > 0)
                    CreateBulletWithDirAndNum(playerBody.fire_left, ref attackDir.left);
                if (attackDir.rigt > 0)
                    CreateBulletWithDirAndNum(playerBody.fire_right, ref attackDir.rigt);
            });

            atkTimer2 = new Timer(secondTime, false, TimeData.One, () =>
            {
                if (attackDir.forward > 0)
                    CreateBulletWithDirAndNum(playerBody.fire_forward, ref attackDir.forward);
                if (attackDir.back > 0)
                    CreateBulletWithDirAndNum(playerBody.fire_back, ref attackDir.back);
                if (attackDir.left > 0)
                    CreateBulletWithDirAndNum(playerBody.fire_left, ref attackDir.left);
                if (attackDir.rigt > 0)
                    CreateBulletWithDirAndNum(playerBody.fire_right, ref attackDir.rigt);
            });
            atkTimer2.Start();
            atkTimer.Start();
        }

    }
}
